package com.yayan.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DataConvertUtil {

	public static Date StringToDate(String dateStr) {

		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = format.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
			//throw new Exception("你输入的日期格式不对");
		}
		return date;
	}
	
	public static String DateToString(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = format.format(date);
		return dateStr;
	}
	
	public static String TimeStampToString(Timestamp stamp){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateStr = format.format(stamp);
		return dateStr;		
	}
	
	public static String getCurrTimeDay() {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		String dateStr = format.format(System.currentTimeMillis());
		return dateStr;
	}
	
	public static String getCurrTime() {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		String dateStr = format.format(System.currentTimeMillis());
		return dateStr;
	}
}
